package com.jiuyou.websocket.service.base;

import com.ruoyi.common.core.domain.entity.Member;
import org.springframework.web.socket.WebSocketSession;

/**
 * websocket 公共service
 */

public class BaseService {

    /**
     * 获取session中的 memberId
     */
    public Long getUserId(WebSocketSession wsSession){
        Object obj = wsSession.getAttributes().get("userId");
        if (null == obj) {
            return null;
        }
        return Long.valueOf(String.valueOf(obj));
    }

    /**
     * 获取session中的 用户member
     */
    public Object getUser(WebSocketSession wsSession){
        Object obj = wsSession.getAttributes().get("user");

        return obj;
    }

    public String getUserKey(WebSocketSession wsSession){
        String userKey="";
        Long userId = getUserId(wsSession);
        String platform=getPlatform(wsSession);
        if(null!=userId){
            userKey=platform+"_"+String.valueOf(userId);
        }
        return userKey;
    }


    /**
     * 获取session中的 openId
     */
    public String getOpenId(WebSocketSession wsSession){
        Object obj = wsSession.getAttributes().get("openId");
        if (null != obj) {
            return (String) obj;
        }
        return null;
    }
    public String getPlatform(WebSocketSession wsSession){
        Object obj = wsSession.getAttributes().get("platform");
        if (null != obj) {
            return (String) obj;
        }
        return null;
    }

}
